package com.bjb.util;

import java.io.File;
import java.io.IOException;

import net.coobird.thumbnailator.Thumbnails;

/**
 * 图片处理工具
 * @author zhangjs
 *
 */
public class ImageProcessTool {
	/**
	 * 按照比例进行压缩
	 * @param sourceFile
	 * @param scale
	 * @param targetFile
	 * @return
	 */
	public static boolean scaleCompression(File sourceFile, float scale, File targetFile){
		try {
			Thumbnails.of(sourceFile).scale(scale).toFile(targetFile);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	/**
	 * 按照大小进行压缩
	 * @param sourceFile
	 * @param width
	 * @param height
	 * @param targetFile
	 * @return
	 */
	public static boolean sizeCompression(File sourceFile, Integer width, Integer height, File targetFile){
		try {
			Thumbnails.of(sourceFile).size(width, height).keepAspectRatio(false).toFile(targetFile);
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
}
